package org.cloudlab.utils;

import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

/**
 * 密码加密及验证工具类
 *
 * @author Liu Yicong
 * @date 2023/9/5
 */
public class PasswordEncoderUtil {
    public static String encodePassword(String password) {
        BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
        return passwordEncoder.encode(password);
    }

    public static boolean matchPassword(String rawPassword, String encodedPassword) {
        BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
        return passwordEncoder.matches(rawPassword, encodedPassword);
    }

    /**
     * peng
     * hqy
     * lhy
     * @param args
     */
    public static void main(String[] args) {
        String raw = "lhy";
        String code = PasswordEncoderUtil.encodePassword(raw);
        System.out.println(code);
        System.out.println(PasswordEncoderUtil.matchPassword(raw, code));
    }
}

